package com.heima.behavior.controller.v1;

import com.heima.behavior.service.*;
import com.heima.model.behavior.dtos.*;
import com.heima.model.behavior.pojos.ApBehaviorEntry;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1")
public class ApLikesBehaviorController {
    @Autowired
    ApBehaviorEntryService apBehaviorEntryService;
    @Autowired
    private ApLikesBehaviorService apLikesBehaviorService;
    @Autowired
    private ApReadBehaviorService apReadBehaviorService;
    @Autowired
    private ApUnlikeBehaviorService apUnlikeBehaviorService;
    @Autowired
    private ApCollectionBehaviorService apCollectionBehaviorService;
    @Autowired
    private ApArticleBehaviorService apArticleBehaviorService;

    @PostMapping("/likes_behavior")
    public ResponseResult like(@RequestBody LikesBehaviorDTO dto) {
        return apLikesBehaviorService.like(dto);
    }

    @PostMapping("read_behavior")
    public ResponseResult read(@RequestBody ReadBehaviorDTO dto) {
        return apReadBehaviorService.readBehavior(dto);
    }

    @PostMapping("/un_likes_behavior")
    public ResponseResult unlikes(@RequestBody UnLikesBehaviorDTO dto) {
        return apUnlikeBehaviorService.unlikeBehavior(dto);
    }


    @PostMapping("/collection_behavior")
    public ResponseResult collectBehavior(@RequestBody CollectionBehaviorDTO dto) {
        return apCollectionBehaviorService.collectBehavior(dto);
    }

    @PostMapping("/article/load_article_behavior")
    public ResponseResult loadarticle(@RequestBody ArticleBehaviorDTO dto) {
        return apArticleBehaviorService.loadArticleBehavior(dto);
    }

    @GetMapping("/behavior_entry/one")
    public ResponseResult<ApBehaviorEntry> findByUserIdOrEquipmentId(@RequestParam(value = "userId", required = false) Integer id,
                                                                     @RequestParam(value = "equipmentId", required = false) int equipmentId) {
        ApBehaviorEntry byUserIdOrEquipmentId = apBehaviorEntryService.findByUserIdOrEquipmentId(id, equipmentId);
        return ResponseResult.okResult(byUserIdOrEquipmentId);

    }


}
